import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getParameter")
public class getParameterServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //预期浏览器会发送一个形如 /getParameter？studentId=123&classId=123的请求
        //借助getParameter获取到query String中的键值对内容
        //getParameter得到的是String类型的结果

        String studentId=req.getParameter("studentId");
        String classId=req.getParameter("classId");

        resp.setContentType("text/html");
        //设置字符集，一定要在返回响应（write）的上面
        resp.setCharacterEncoding("utf8");
        resp.getWriter().write("学生Id= "+studentId+"  "+"班级Id="+classId);
    }
}
